import QtQuick 2.12
import QtQuick.Window 2.12
import Models.User 1.0
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("qml demo")

    GridLayout
    {
        anchors.centerIn: parent
        width:300
        columnSpacing: 10
        rowSpacing: 10
        rows:4
        columns:2

        Item{
            Layout.row: 0
            Layout.column: 0
            width:100
            height:30
            Text{
                text:"Name:"
                anchors.centerIn: parent
            }
        }
        Item{
            Layout.row: 0
            Layout.column: 1
            Layout.fillWidth: true
            height:30
            TextField{
                anchors.verticalCenter: parent.verticalCenter
                width:parent.width
                height:24
                id:textfield_Name
                text: testUserModel.Name
                onEditingFinished: {
                    testUserModel.Name = textfield_Name.text;
                }
            }
        }

        Item{
            Layout.row: 1
            Layout.column: 0
            width:100
            height:30
            Text{
                text:"password:"
                anchors.centerIn: parent
            }
        }
        Item{
            Layout.row: 1
            Layout.column: 1
            Layout.fillWidth: true
            height:30
            TextField{
                anchors.verticalCenter: parent.verticalCenter
                width:parent.width
                height:24
                id:textfield_Password
                text:testUserModel.Password
                onEditingFinished: {
                    testUserModel.Password = textfield_Password.text;
                }
            }
        }

        Item{
            Layout.row: 2
            Layout.column: 0
            Layout.fillWidth: true
            height: 20
            Layout.columnSpan: 2
            RowLayout{
                anchors.centerIn: parent
                Button{
                    id:button_OK
                    text:"OK"
                    onClicked:{
                        if(testUserModel.checkPass()){
                            loginstatus.text = "login success!"
                        }else{
                            loginstatus.text = "login fail!"
                        }

                        text_Msg.visible = true;
                    }
                }
                Button{
                    id:button_Cancel
                    text:"cancel"
                    onClicked: {
                        Qt.quit();
                    }
                }
            }
        }

        Item{
            Layout.row: 3
            Layout.column: 0
            width:100
            height:30
            Text{
                text:"the name last char is :"
                anchors.centerIn: parent
            }
        }

        Item{
            Layout.row: 3
            Layout.column: 1
            Layout.fillWidth: true
            height: 30
            Layout.columnSpan: 2
            Text {
                id: text_Msg
                objectName: "text_Msg"
                text: testUserModel.Message
                anchors.fill: parent
                verticalAlignment: Qt.AlignVCenter
            }
        }

        Item{
            Layout.row: 4
            Layout.column: 0
            width:100
            height:30
            Text{
                text:"name sub string number:"
                anchors.centerIn: parent
            }
        }

        Item{
            Layout.row: 4
            Layout.column: 1
            Layout.fillWidth: true
            height: 30
            Layout.columnSpan: 2
            Text {
                id: msgCount
                objectName: "msgCount"
                text: testUserModel.SubLength
                anchors.fill: parent
                verticalAlignment: Qt.AlignVCenter
                visible: true
            }
        }

        Item{
            Layout.row: 5
            Layout.column: 0
            width:100
            height:30
            Text{
                id:loginstatus
                text: "Please login..."
                anchors.centerIn: parent
            }
        }

    }
}
